package lang;

import lang.service.OrderService2;

import java.util.HashMap;
import java.util.Map;

public class OrderService {


    private static Map<String, String> map = new HashMap() {
        {
            put("M01", "lang.service.M01OrderServiceImpl");
            put("M02", "lang.service.M02OrderServiceImpl");
            put("M03", "lang.service.M03OrderServiceImpl");
        }
    };

    public static Map<String, String> getMap() {
        return map;
    }

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        OrderService orderService = new OrderService();
        Order order = new Order();
        order.setOrderType(OrderType.M01);

        orderService.discount(order);
    }


    public double discount(Order order) throws ClassNotFoundException, IllegalAccessException, InstantiationException {

        if (!OrderService.getMap().containsKey(order.getOrderType().name())) {
            new RuntimeException("不支持的业务类型");
        }

        String clazzName = OrderService.getMap().get(order.getOrderType().name());

        Class classw = Class.forName(clazzName);

        OrderService2 orderService2 = (OrderService2) classw.newInstance();

        Order orderSync = orderService2.orderSync(order);

        double discount1 = orderSync.getDiscount();

        System.out.println(discount1);

        return discount1;
    }


}

